package com.example.svn.demos.service.impl;

import com.example.svn.demos.service.BasicService;

import com.profesorfalken.jpowershell.PowerShell;
import com.profesorfalken.jpowershell.PowerShellResponse;
import org.apache.commons.io.input.BOMInputStream;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;

@Service
public class BasicServiceImpl implements BasicService {


    @Override
    public boolean editPassword(String userName, String newPassword) {
        try {

            String cmd = "$svnuser = Get-WmiObject -Namespace Root\\VisualSVN -ComputerName localhost -query \"select * from VisualSVN_User where name = '"+userName+"'\";$svnuser.SetPassword('"+newPassword+"')";
            PowerShellResponse powerShellResponse = PowerShell.executeSingleCommand(cmd);
            System.out.println(powerShellResponse.getCommandOutput());

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
